/****************************************************** 
 *	Code by Utkarsh Sinha
 *	Based on JIFT by Jun Liu
 *	Visit http://aishack.in/ for more indepth articles and tutorials
 *	on artificial intelligence
 * Use, reuse, modify, hack, kick. Do whatever you want with
 * this code :)
 ******************************************************/

// MySIFT.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

#include "SIFT.h"

#include <opencv\cv.h>
#include <opencv\highgui.h>

#include <opencv2\features2d\features2d.hpp>

// The main function!
int main()
{


	CvCapture * capture = 0; 

    IplImage *frame, *frame_copy = 0;

	capture = cvCaptureFromCAM(0);

	cvNamedWindow("camera", 1);

	if (capture)
	{
		for (;;)
		{
			
			if( !cvGrabFrame( capture ))
                break;
            frame = cvRetrieveFrame( capture );

			 // Allocate framecopy as the same size of the frame
            if( !frame_copy )
                frame_copy = cvCreateImage( cvSize(frame->width,frame->height),
                                            IPL_DEPTH_8U, frame->nChannels );

            // Check the origin of image. If top left, copy the image frame to frame_copy. 
            if( frame->origin == IPL_ORIGIN_TL )
                cvCopy( frame, frame_copy, 0 );
            // Else flip and copy the image
            else
                cvFlip( frame, frame_copy, 0 );

			cvShowImage("camera", frame_copy);
			
			// -------------------------- AISHACK implementation --> slow
			/*
			SIFT *sift = new SIFT(frame_copy,4,2);

			sift->DoSift();
			sift->ShowKeypoints();
			*/
			// -----------------------------------------

			 CvSeq* objectKeypoints = 0, *objectDescriptors = 0;
			 CvSeq* imageKeypoints = 0, *imageDescriptors = 0;

			 CvSURFParams params = cvSURFParams(500, 1);






			 // Wait for a while before proceeding to the next frame
            if( cvWaitKey( 10 ) >= 0 )
                break;
			
		}
	}

	cvWaitKey(10);


	// Create an instance of SIFT
	// SIFT *sift = new SIFT("house.jpg", 4, 2);
	/*
	sift->DoSift();				// Find keypoints
	sift->ShowAbsSigma();		// Display the sigma table
	sift->ShowKeypoints();		// Show the keypoints
	cvWaitKey(0);				// Wait for a keypress

	// Cleanup and exit
	delete sift;
	return 0; */
}

